﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Reporter.Data;
using ReporterControlLibrary.Models;
using System.Collections.Specialized;

namespace Reporter.Controls
{
    /// <summary>
    /// Interaction logic for ProjectUserControl.xaml
    /// </summary>
    public partial class ProjectUserControl : UserControl
    {

        public ProjectUserControl()
        {
            InitializeComponent();

            ((INotifyCollectionChanged)reportInfo_lb.Items).CollectionChanged += new NotifyCollectionChangedEventHandler(ProjectUserControl_CollectionChanged);

        }

        void ProjectUserControl_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {

            var currentProject = this.DataContext as Project;

            if (currentProject != null && currentProject.ReportInfos != null)
            {
                foreach (var item in currentProject.ReportInfos)
                {
                    item.IsLastItem = false;
                }

                if (this.reportInfo_lb.Items.Count > 0)
                {
                    var ri = (this.reportInfo_lb.Items[reportInfo_lb.Items.Count - 1] as ReportInfo);
                    if (ri != null)
                        ri.IsLastItem = true;
                }
            }
        }
    }
}